package com.springcloud.demo.dynamicTable.autocode.utils;

public class DataTypeUtils {
    // 数据库类型，默认pg，启动时读取
    public static DatabaseType databaseType = DatabaseType.MYSQL;
    private static final String STRING = "String";
    private static final String INTEGER = "Integer";
    private static final String DOUBLE = "Double";
    private static final String LONG = "Long";
    private static final String FLOAT = "Float";
    private static final String BOOLEAN = "Boolean";
    private static final String DATE = "Date";

    public static String transform2PostgreSql(String javaType) {
        String result;
        switch (javaType) {
            case STRING:
                result = "varchar";
                break;
            case INTEGER:
                result = "int4";
                break;
            case LONG:
                result = "int8";
                break;
            case DOUBLE:
                result = "float8";
                break;
            case FLOAT:
                result = "float4";
                break;
            case BOOLEAN:
                result = "bool";
                break;
            case DATE:
                result = "timestamp";
                break;
            default:
                result = "";
                break;
        }
        return result;
    }

    public static String transform2MySql(String javaType) {
        String result;
        switch (javaType) {
            case STRING:
                result = "varchar";
                break;
            case INTEGER:
                result = "integer";
                break;
            case LONG:
                result = "bigint";
                break;
            case DOUBLE:
                result = "double";
                break;
            case FLOAT:
                result = "float";
                break;
            case BOOLEAN:
                result = "bit";
                break;
            case DATE:
                result = "timestamp";
                break;
            default:
                result = "";
                break;
        }
        return result;
    }

    public static String getColumnDefaultLength(String javaType) {
        String result;
        switch (javaType) {
            case STRING:
                result = "255";
                break;
            case INTEGER:
                result = "8";
                break;
            case LONG:
                result = "16";
                break;
            case DOUBLE:
                result = "10, 4";
                break;
            case FLOAT:
                result = "10, 2";
                break;
            case BOOLEAN:
                result = "1";
                break;
            case DATE:
                result = "6";
                break;
            default:
                result = "36";
                break;
        }
        return result;
    }
}
